package com.itguigu.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.jdbc.core.JdbcTemplate;

@Configuration //配置类
@PropertySource("classpath:jdbc.properties") // 引入外部配置文件注解
@ComponentScan("com.itguigu")
public class JavaConfig {

    @Bean
    public DruidDataSource dataSource(@Value("${atguigu.url}") String url, @Value("${atguigu.driver}") String driverClassName,
                                      @Value("${atguigu.username}") String username, @Value("${atguigu.password}") String password) {
        DruidDataSource dataSource = new DruidDataSource();

        dataSource.setUrl(url);
        dataSource.setDriverClassName(driverClassName);
        dataSource.setUsername(username);
        dataSource.setPassword(password);

        return dataSource;
    }



}
